jQuery(document).ready(function($) {
	var $stick = $('#sidebar-fix'),
		theWindow = $(window),
		oldTop = $stick.offset().top,
		_li=$('#sidebar-nav li'),
		_lia = $('#sidebar-nav li a'),
		_tab = $('#sidebar-tab li.tab'),
		_top = $('#top'),
		_body = window.opera ? document.compatMode == "CSS1Compat" ? $("html") : $("body") : $("html,body");
		auto = function(){
			var n = _li.length - 1,
				_current = $('#sidebar-nav li.selected'),
				m = _li.index(_current);
			m = m < n ? (m+1):0;
			_lia.eq(m).click();
		};
	_top.click(function(e){
		e.preventDefault();
		_body.animate({scrollTop: 0},1600);
		return false;
	});
	theWindow.scroll(function() {
		var top = theWindow.scrollTop();
		if (top  >= oldTop) {
			$stick.css({
				/*position: 'fixed',*/
				top: 30
			})
		} else if (top < oldTop) {
			$stick.css({
				/*position: 'relative',*/
				top: ''
			})
		}
	});
	_lia.click(function(e){
		e.preventDefault();
		var _this = $(this),
			_parent = _this.parent();
		if(_parent.hasClass('selected')) return false;
		var n = _li.index(_parent),
			_current = $('#sidebar-tab li.tab.selected'),
			m = _li.index($('#sidebar-nav li.selected'));
		if(m<n){
			var left_n = 300,
				left_m = -300;
		}else{
			var left_n = -300,
				left_m = 300;			
		}
		_li.removeClass('selected');
		_parent.addClass('selected');
		_current.stop().animate({left:left_m},500,function(){
			$(this).removeClass('selected');
		});
		_tab.eq(n).css("left",left_n).addClass('selected').stop().animate({left:0},500);
		return false;
	});
	var time = setInterval(auto, 5000);
	$('#sidebar-nav,#sidebar-tab').hover(function() {
		clearInterval(time);
		time = null
	}, function() {
		clearInterval(time);
		time = null;
		time = setInterval(auto, 5000)
	});
//back-to-top
	$('#toolBackTop').hide();
    $(window).scroll(function() {
        if ($(this).scrollTop()>100) {
            $('#toolBackTop').fadeIn();
        } else {
            $('#toolBackTop').fadeOut();
        }
    });
    $('#toolBackTop a').click(function() {
        $("body,html").animate({
            scrollTop:0
        },800);
        return false;
    });
//侧边栏随窗口滚动
var old = $('#sidebar-fixed').offset().top;
	$(window).scroll(function() {
		var t = $(this).scrollTop();
		if (t - 20 > old) {
			$('#sidebar-fixed').addClass('fixed')
		} else {
			$('#sidebar-fixed').removeClass('fixed')
		}
	}); 
//
$('#tab-title span').click(function(){
 
	$(this).addClass("selected2").siblings().removeClass();
 
	$("#tab-content > ul").slideUp('1500').eq($('#tab-title span').index(this)).slideDown('1500');
 
});
	//reply @
$('.vcard').click(function() {
    var atid = '"#' + $(this).parent().parent().parent().attr("id") + '"';
    var atname = $(this).children('a').text();
$("#comment").attr("value","<a href=" + atid + ">@" + atname + "</a>" + " ：").focus();
});
$("#cancel-comment-reply a").click(function() {
$("#comment").attr("value",'');
});
//dblcilick reply commets
	$('.comment-body').dblclick(function(){
		if($(this).parent().next('.respond').length>0){
			$('#cancel-comment-reply-link').click(); 
		}else{
			$(this).children('.vcard').children('span').children('a').click();
		}
		return false;
	});
//title tips
  $(function() {
                $("#sidebar img,.sidebarreader a,#sidebar-fix a,.post-content a,.post-title a").each(function(b) {
                        if (this.title) {
                                var c = this.title;
                                var a = 30;
                                var x = 20;
                                $(this).mouseover(function(d) {
                                        this.title = "";
                                        $("body").append('<div id="tooltip">' + c + "</div>");
                                        $("#tooltip").css({
                                                left: (d.pageX + a) + "px",
                                                top: (d.pageY + x) + "px",
                                                opacity: "0.8"
                                        }).show(250)
                                }).mouseout(function() {
                                        this.title = c;
                                        $("#tooltip").remove()
                                }).mousemove(function(d) {
                                        $("#tooltip").css({
                                                left: (d.pageX + a) + "px",
                                                top: (d.pageY + x) + "px"
                                        })
                                })
                        }
                })
        });

	
//
	
});